package com.aabte.controller;

import com.aabte.dao.IUser;
import com.aabte.model.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1")
@Api(value = "/v1", description = "这是我第一个版本的demo")
public class Demo {

    @Autowired
    private SqlSessionTemplate sqlST;

    // @Autowired
    private IUser userDao;

    @GetMapping("/getUserCount")
    @ApiOperation(value = "获取用户数", httpMethod = "GET")
    public int getUserCount(){
        // IUser mapper = sqlST.getMapper(IUser.class);
        // return mapper.getUserCount();

        return sqlST.selectOne("getUserCount");
    }

    @PostMapping("/addUser")
    @ApiOperation(value = "新增用户", httpMethod = "POST")
    public int addUser(@RequestBody User user){
        return sqlST.insert("addUser", user);
    }

    @PutMapping("/updateUser")
    @ApiOperation(value = "更新用户", httpMethod = "PUT")
    public int updateUser(@RequestBody User user) {
        return sqlST.update("updateUser", user);
    }

    @DeleteMapping("/deleteUser/{id}")
    @ApiOperation(value = "删除用户", httpMethod = "DELETE")
    public int deleteUser(@PathVariable Integer id) {
        return sqlST.delete("deleteUser", id);
    }

}
